package com.zxy.controller;

import com.zxy.model.Category;
import com.zxy.model.CategoryQuery;
import com.zxy.model.Product;
import com.zxy.model.ProductQuery;
import com.zxy.service.CategoryService;
import com.zxy.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/product")
//restFul
public class ProductController {

    @Autowired
    private ProductService productService;
    @GetMapping//http://a.com?a=1&b=2  //http://a.com?id=1&name=张三
    public List<Product> select(ProductQuery query){
      return  productService.select(query);
    }

    @PostMapping//通过 RequestBody 请求体 传过来的json数据 给我们自动转为Category 这个对象
    public int insert(@RequestBody Product product){
        return productService.insert(product);
    }

    @PutMapping//通过 RequestBody 请求体 传过来的json数据 给我们自动转为Category 这个对象
    public int update(@RequestBody Product product){

        return productService.update(product);
    }

    @DeleteMapping//http://a.com?id=1&name=张三
    public int delete(Integer id){
        return productService.delete(id);
    }

}
